<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>


    <style>
        * {
            padding: 0;
            margin: 0;
            list-style: none;
        }

        ul {
            width: 600px;
            height: 40px;
            background-color: pink;
            display: flex;
            margin: 50px auto;
        }

        ul li {

            flex: 1;
            text-align: center;
        }

        .active {
            width: 30px;
            height: 4px;
            background-color: red;
            transform: translate(503px, 80px);
            transition: all 1s;
        }

        .color {
            color: red;
        }
    </style>


</head>

<body>
    <div class="active"></div>
    <ul>
        <li class="color" data-id="0">111</li>

        <li data-id="1">
            111
        </li>
        <li data-id="2">111</li>
        <li data-id="3">111</li>
        <li data-id="4">111</li>
        <li data-id="5">111</li>
    </ul>

    <script>
        const ul = document.querySelector('ul')
        const li = document.querySelector('ul li')
        const active = document.querySelector('.active')
        ul.addEventListener('click', function (e) {
            const i = e.target.dataset.id
            const s = e.target.offsetLeft
            if (e.target.tagName === 'LI') {
                document.querySelector('.color').classList.remove('color')
                e.target.classList.add('color')
                active.style.transform = `translate(${s + 35}px, 80px)`
            }

        })
    </script>
</body>

</html>